<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>店铺管理</title>
	<meta name="decorator" content="ani"/>
	<script type="text/javascript">

		$(document).ready(function() {
			
			getCategory();
			
			$("#inputForm").validate({
				submitHandler: function(form){
					
					if ($("#belongToBigCategory").val() == "" || $("#belongToBigCategory").val() == undefined || typeof ($("#belongToBigCategory").val()) == "undefined"){
                        top.layer.alert('请至少选择一个大的分类!', {icon: 0, title:'警告'});
                        return ;
					}
				    if ($("#belongSonCategory").val() == "" || $("#belongSonCategory").val() == undefined || typeof ($("#belongSonCategory").val()) == "undefined"){
                        top.layer.alert('请至少选择一个详细分类!', {icon: 0, title:'警告'});
                        return ;
					}
					$("#bigCategoryId").val($("#belongToBigCategory").val());
					$("#categoryID").val($("#belongSonCategory").val());
					
					
					jp.loading();
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
		//获取大分类
		function getCategory(){
			$.ajax({
                url: "${ctx}/anny/shop/annyShopCategory/categoryData?level=1",
                type: "POST",
                dataType: "json",
                success: function(result) {
					var belongBigHtml = '';
					belongBigHtml += "<select id=\"belongToBigCategory\" name=\"belongBigCategory\" class=\"form-control valid\" onchange=\"getCategorySonSelect(this.value)\" aria-invalid=\"false\">";
					belongBigHtml += "<option value=\"\">请选择分类</option>";
					if(result.data != null && "" != result.data){
						for (var i = 0; i < result.data.length; i++) {
							if($("input[name='bigCategoryId']").val() == result.data[i].id){
								belongBigHtml += "<option selected='selected' value=\""+result.data[i].id+"\">"+result.data[i].name+"</option>";
							}else{
								belongBigHtml += "<option value=\""+result.data[i].id+"\">"+result.data[i].name+"</option>";
							}
						}
					}
					belongBigHtml += "</select>";
					belongBigHtml += "<select id=\"belongSonCategory\"  name=\"belongSonCategory\" class=\"form-control valid\" aria-invalid=\"false\">";
					belongBigHtml += "<option value=\"\">请选择分类</option></select>";
					console.log(belongBigHtml.length);
					if(belongBigHtml.length == 335){
                        belongBigHtml = "所属分类未配置";
                    } 
					$("#belongBigCategory").append(belongBigHtml);
					
					if("" != $("input[name='bigCategoryId']").val() && null != $("input[name='bigCategoryId']").val()){
						getCategorySonSelect($("input[name='bigCategoryId']").val());
		          	}
                }
                
            });
		}
		//获取小分类列表并选中
        function getCategorySonSelect(parentId){
        	$("#belongSonCategory").empty();
			console.log(parentId);
			if (parentId == '' || parentId == null || parentId.length == 0){
                top.layer.alert('请至少选择一个分类!', {icon: 0, title:'警告'});
                return ;
			}
        	$.ajax({
                url: "${ctx}/anny/shop/annyShopCategory/categoryData?level=2&parentId="+ parentId,
                type: "POST",
                dataType: "json",
                success: function(result) {
					if(result.code == 0){
						var belongHtml = '<option value=\"\">请选择分类</option>';
						for (var i = 0; i < result.data.length; i++) {
							if($("input[name='categoryID']").val() == result.data[i].id){
								belongHtml += "<option selected='selected' value=\""+result.data[i].id+"\">"+result.data[i].name+"</option>";
							}else{
								belongHtml += "<option value=\""+result.data[i].id+"\">"+result.data[i].name+"</option>";
							}
						}
						$("#belongSonCategory").html(belongHtml);
					}
                }
                
            });
        }
	</script>
</head>
<body>
<div class="wrapper wrapper-content">				
<div class="row">
	<div class="col-md-12">
	<div class="panel panel-primary">
		<div class="panel-heading">
			<h3 class="panel-title"> 
				<a class="panelButton" href="${ctx}/anny/shop/annyShop"><i class="ti-angle-left"></i> 返回</a>
			</h3>
		</div>
		<div class="panel-body">
		<form:form id="inputForm" modelAttribute="annyShop" action="${ctx}/anny/shop/annyShop/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<form:hidden path="categoryID" id="categoryID" />
		<form:hidden path="bigCategoryId" id="bigCategoryId" />
		<sys:message content="${message}"/>	
				<div class="form-group">
					<label class="col-sm-2 control-label"><font color="red">*</font>店铺名称：</label>
					<div class="col-sm-10">
						<form:input path="shopName" htmlEscape="false"    class="form-control required"/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label"><font color="red">*</font>是否为线上店铺：</label>
					<div class="col-sm-10">
						<form:select path="onlineFlag" class="form-control required">
							<form:option value="" label=""/>
							<form:options items="${fns:getDictList('yes_no')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label"><font color="red">*</font>联系人：</label>
					<div class="col-sm-10">
						<form:input path="contactName" htmlEscape="false"    class="form-control required"/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label"><font color="red">*</font>联系电话：</label>
					<div class="col-sm-10">
						<form:input path="contactTel" htmlEscape="false"    class="form-control required"/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label"><font color="red">*</font>所属区域：</label>
					<div class="col-sm-10">
						<form:input path="areaId" htmlEscape="false"    class="form-control required"/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label"><font color="red">*</font>详细地址：</label>
					<div class="col-sm-10">
						<form:input path="detailAdd" htmlEscape="false"    class="form-control required"/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label"><font color="red">*</font>客服电话：</label>
					<div class="col-sm-10">
						<form:input path="hotline" htmlEscape="false"    class="form-control required"/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label"><font color="red">*</font>审批标识：</label>
					<div class="col-sm-10">
						<form:input path="approvalStatus" htmlEscape="false"    class="form-control required"/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label"><font color="red">*</font>浏览量：</label>
					<div class="col-sm-10">
						<form:input path="numOfBrowse" htmlEscape="false"    class="form-control required"/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label"><font color="red">*</font>店铺总订单数：</label>
					<div class="col-sm-10">
						<form:input path="numOFOrder" htmlEscape="false"    class="form-control required"/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label"><font color="red">*</font>店铺总收藏数：</label>
					<div class="col-sm-10">
						<form:input path="numOfFavorites" htmlEscape="false"    class="form-control required"/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label"><font color="red">*</font>店铺评价得分：</label>
					<div class="col-sm-10">
						<form:input path="sorce" htmlEscape="false"    class="form-control required"/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label"><font color="red">*</font>营业范围：</label>
					<div class="col-sm-10">
						<form:input path="businessScope" htmlEscape="false"    class="form-control required"/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label"><font color="red">*</font>营业时间：</label>
					<div class="col-sm-10">
						<form:input path="businessHours" htmlEscape="false"    class="form-control required"/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label"><font color="red">*</font>用户ID：</label>
					<div class="col-sm-10">
						<form:input path="userId" htmlEscape="false"    class="form-control required"/>
					</div>
				</div>
				<%-- <div class="form-group">
					<label class="col-sm-2 control-label">店铺等级：</label>
					<div class="col-sm-10">
						<form:input path="level" htmlEscape="false"    class="form-control "/>
					</div>
				</div> --%>
				<div class="form-group">
					<label class="col-sm-2 control-label"><font color="red">*</font>店铺类型：</label>
					<div class="col-sm-10" id="belongBigCategory">
<%-- 						<form:input path="bigCategoryId" htmlEscape="false"    class="form-control "/> --%>
					</div>
				</div>
				<%-- <div class="form-group">
					<label class="col-sm-2 control-label">类别ID：</label>
					<div class="col-sm-10" id="">
						<form:input path="categoryID" htmlEscape="false"    class="form-control "/>
					</div>
				</div> --%>
				<div class="form-group">
					<label class="col-sm-2 control-label"><font color="red">*</font>关闭店铺标识(0，开店，1，闭店)：</label>
					<div class="col-sm-10">
<%-- 						<form:input path="closeShopFlag" htmlEscape="false"    class="form-control "/> --%>
						<form:select path="closeShopFlag" class="form-control required">
							<form:option value="" label=""/>
							<form:options items="${fns:getDictList('anny_shop_closeShopFlag')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select>
					</div>
				</div>
		<c:if test="${fns:hasPermission('anny:shop:annyShop:edit') || isAdd}">
				<div class="col-lg-3"></div>
		        <div class="col-lg-6">
		             <div class="form-group text-center">
		                 <div>
		                     <button class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="正在提交...">提 交</button>
		                 </div>
		             </div>
		        </div>
		</c:if>
		</form:form>
		</div>				
	</div>
	</div>
</div>
</div>
</body>
</html>